home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11713 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  48 lines

  1. Path: news.netins.net!trg1
  2. From: hhowe@trgnet.com (Harold Howe)
  3. Newsgroups: comp.lang.c++
  4. Subject: Object constuction in function call.
  5. Date: Fri, 15 Mar 96 20:21:33 GMT
  6. Organization: Technology Resource Group
  7. Message-ID: <4icmqh$8g6@insosf1.netins.net>
  8. NNTP-Posting-Host: desm-21-00.dialup.netins.net
  9. X-Newsreader: News Xpress Version 1.0 Beta #3
  10.  
  11. Greetings.
  12.  
  13. I need help.  If an object is contructed in a function call, how long does it 
  14. exist.  For example, (this is not what I am doing, but it illustrates the 
  15. point).
  16.  
  17. class TCorners
  18.   {
  19.   public:
  20.     int w,x,y,z;
  21.     TCorners( int a, int b, int c, int d) 
  22.       { w=a;   x=b; y=c;  z=d;}
  23.   } 
  24.  
  25. void display_coordinates(TCorners corners)
  26.   {
  27.   cout << "corners are" << corners.w << corners.x
  28.                         << corners.y << corners.z ;
  29.   }
  30.  
  31. int main(void)
  32.   {
  33.   display_coordinates(TCorners(1,1,20,10));
  34.   display_coordinates(TCorners(1,5,25,15));
  35.   display_coordinates(TCorners(2,5,20,10));
  36.   }
  37.   
  38. How many objects exist at the programs end?  Are the objects created for the 
  39. function call, then nuked afterwards?  I think they hang around, in fact I 
  40. know they hang around because if I call the display guy about 100 times the 
  41. program finally blows up.  I would like to use this syntax if possible in the 
  42. real program that I am writing.
  43.  
  44. Any suggestions would be appreciated.
  45. Harold Howe
  46. hhowe@trgnet.com   
  47.  
  48.